import axios, { AxiosError } from '../../src'

// 404
axios({
  url: '/error/get1'
}).then(res => {
  console.log(res)
}).catch(reason => {
  console.log(reason)
})

// 500
axios({
  url: '/error/get',
  responseType: 'json'
}).then(res => {
  console.log(res)
}).catch(reason => {
  console.log(reason)
})

// Mock network error
setTimeout(() => {
  axios({ url: '/error/get' }).then(res => {
    console.log(res)
  }).catch(reason => {
    console.log(reason)
  })
}, 6000)

// timeout
axios({
  url: '/error/timeout',
  timeout: 1000
}).then(res => {
  console.log(res)
}).catch((err: AxiosError) => {
  console.log(err.message)
  Object.keys(err).forEach((key) => {
    const value = err[key]
    typeof value !== 'undefined' && console.log(value)
  })
})
